package com.webtest.demo;

import java.util.List;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import bsh.This;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;

public class CrossearthPage {

	AndroidDriver  driver;
	BaseAction action;
	
	public CrossearthPage(AndroidDriver driver) {
		this.driver = driver;
		this.action= new BaseAction(driver);
	}
	
	
	//一、点击软件后的首页面	
	//1.点击开启纵横
	public WebElement startCrossearth() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/begain"));
	}


	//二、真知板块页面
	//1.在真知板块，点击返回主页面
	public WebElement trueknowledgebackMainPage() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/back_button"));
	}	
	//2.获取以往的历史事件
	public WebElement historicalEvents(int i) {
		WebElement list=driver.findElement(AppiumBy
				.id("com.software.crossearth:id/recycler_view"));		
		List<WebElement> items=list.findElements(AppiumBy
				.className("android.widget.LinearLayout"));		
		//获取当页第i个历史事件
		WebElement historicalevents= items.get(i);
		return historicalevents;
	};
	//3.获取真知板块朝代
	public WebElement trueknowledgeDynasty(int i) {
		WebElement list=driver.findElement(AppiumBy
				.id("com.software.crossearth:id/design_navigation_view"));		
		List<WebElement> items=list.findElements(AppiumBy
				.className("androidx.appcompat.widget.LinearLayoutCompat"));		
		//获取当页第i个朝代
		WebElement dynasty= items.get(i);
		return dynasty;
	};	

	//一、点击软件后的首页面	
	//1.单击开始按钮进入CrossEarth登陆页面
	public void homepage() throws InterruptedException {
		action.click(this.startCrossearth());
	}

	//2.Shift + Tab + Enter进入CrossEarth登录页面
	public void shifttabenterHomepage() throws InterruptedException{
		action.pressShiftTab();
		//action.pressEnterKey();
	}
	
	//3.Ctrl + A + Enter + Enter进入CrossEarth登陆页面
	public void ctrladoubleenterHomepage() throws InterruptedException {
		action.pressctrlkeyenter('A');
		Thread.sleep(500);
		//action.pressEnterKey();
	}
	
	//4.Enter + Enter进入CrossEarth登陆页面
	public void doubleenterHomepage() throws InterruptedException {
		action.pressEnterKey();
		//action.pressEnterKey();
	}
	
	//5.Enter选中开始标志后释放，再单击进入CrossEarth登陆页面
	public void releaseenterHomepage() throws InterruptedException {
		//action.pressEnterKey();
		//页面其他地方clickable为false，可用坐标进行点击
		action.click(1328, 438);
		action.click(this.startCrossearth());
	}
	

	//二、真知板块页面
	//42.查看创作模块能否正常打开
	public void opentruthModules() throws InterruptedException {
		action.click(historicalknowledge());
		action.swipe(354, 1386, 354, 311);	
	}
	
	//43.使用键盘方向键进行翻页操作
	public void keybordturnpagetruthmodule() throws InterruptedException {
		action.click(historicalknowledge());
		for(int i=0;i<9;++i) {
			action.pressTabKey();
			Thread.sleep(200);
		}
		action.pressEnterKey();
		Thread.sleep(200);
		action.navigateBack();
		
	}
	
	//44.使用鼠标单机事件进行查看第四个故事
	public void mouseclicktruthModules() throws InterruptedException {
		action.click(historicalknowledge());
		action.click(this.historicalEvents(5));
		action.navigateBack();
		action.click(this.trueknowledgebackMainPage());
		Thread.sleep(200);
	}
	
	//45.鼠标侧拉选择秦朝
	public void mousesidepulltruthModules() throws InterruptedException {
		//action.click(this.quickLogin());
		action.click(historicalknowledge());
		action.clickAndDrag(894, 693, 774, 693);
		Thread.sleep(300);
		action.click(this.trueknowledgeDynasty(6));
	}

}
